﻿@model IEnumerable<BookClubPortal.Models.Book>
@{
    var grid = new WebGrid(Model, defaultSort:"Name", canPage:true,rowsPerPage:10);
}
@helper Truncate(string
input, int length)
    {
        if(input!=null)
        {
        
             if (input.Length <= length)
             {
                @input
             }
             else
             {
                @input.Substring(0, length)<text>...</text>
             }
        }
} 

@{
    ViewBag.Title = "Manage";
}

<h2>Manage your own books</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>

@grid.GetHtml(columns: grid.Columns(

grid.Column("ImageURL", header: "Image",format: @<text><a href="@item.ImageURL" target="_blank"><img src="@item.ImageURL" alt="@item.Title" onerror="AltImage(this,'@Url.Content("~/Content/Images/logo.png")')" width="50" height="50"></a></text>),
grid.Column("Title", format: @<text>@Truncate(@item.Title,30)</text>),
        grid.Column("Author", format: @<text>@Truncate(@item.Author, 30)</text>),
                        grid.Column("ReleaseYear", header: "Release Year"),
                        grid.Column("Genre.Name", header: "Genre", format: @<text>@Truncate(@item.Genre.Name, 30)</text>),
                            grid.Column("Description", header: "Description", format: @<text>@Truncate(@item.Description, 30)</text>),
                            grid.Column(columnName: "Actions",
                            format: (book) =>
                            {
                                var links = @Html.ActionLink("Edit", "Edit", new { id = book.BookId }) + "|" +
                                @Html.ActionLink("Details", "Details", new { id = book.BookId }) + "|" +
                                @Html.ActionLink("Delete", "Delete", new { id = book.BookId });
                                return Html.Raw(links);
                            }
                                    ))
                                )

@section Scripts {
    @Scripts.Render("~/bundles/tools")
}


